﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Frame.Lib.Core.Base;
using Frame.Lib.Common;

namespace Frame.Lib.Core.Log.Exceptions
{
    public class LogExceptionBO : CommonOperate<LogExceptionInfo>//, ILog<LogExceptionInfo>
    {
        private LogExceptionDAL _exceptionLog;

        protected override BaseDAL DAL
        {
            get
            {
                return _exceptionLog;
            }
        }
        public LogExceptionBO()
        {
            _exceptionLog = new LogExceptionDAL();
        }

        public void Write(Exception ex, string tag)
        {           
            LogExceptionInfo info = new LogExceptionInfo();
            info.ID = Guid.NewGuid();
            info.InputTime = DateTime.Now;
            info.StackTrace = ex.StackTrace;
            info.ErrorMessage = ex.Message + "(" + ex.GetType().Name + ")";
            info.Tag = tag;
            if (AppSession.LoginName != null)
            {
                info.LoginName = AppSession.LoginName;
                info.UserName = AppSession.UserName;
            }
            Save(info, true);
        }

        public void Delete()
        {
            _exceptionLog.Delete();
        }

        public void Delete(string startTime, string endTime)
        {
            _exceptionLog.Delete(startTime, endTime);

        }
      
        #region ILog<ErrorLogInfo> 成员

        //public IEnumerable<LogExceptionInfo> GetList(PagerSortSetting setting, string startTime, string endTime)
        //{
        //    return _exceptionLog.GetList(setting, startTime, endTime);
        //}

        //public void Delete()
        //{
        //    _exceptionLog.Delete();
        //}

        //public void Delete(string startTime, string endTime)
        //{
        //    _exceptionLog.Delete(startTime, endTime);
        //}

        #endregion
    }
}
